package com.yescall.mole.screen;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.tablelayout.Table;
import com.yescall.mole.Mole;
import com.yescall.mole.MoleGame;

public class MainScreen extends AbstractScreen {
	private Texture moleTexture;
	private TextureRegion moleRegion;
	private TextureRegion moleBackRegion;
	Table table;
	
	private ArrayList<Mole> moleArray = new ArrayList<Mole>();

	public MainScreen(MoleGame game) {
		super(game);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void show(){
        super.show();
        TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("texture/texture.pack"));
        //Sprite spr = atlas.createSprite("test01");
        //moleTexture = atlas.findRegion("test01").getTexture();
        //moleTexture.setFilter( TextureFilter.Linear, TextureFilter.Linear );
        //moleRegion = new TextureRegion( moleTexture, 0, 0, 256, 256 );
        moleRegion = atlas.findRegion("test01");
        moleBackRegion = atlas.findRegion("test03 (multi shapes)");
        
        moleArray.add(Mole.create(moleRegion));
        moleArray.add(Mole.create(moleRegion));
        moleArray.add(Mole.create(moleRegion));
        
        moleArray.add(Mole.create(moleRegion));
        moleArray.add(Mole.create(moleRegion));
        moleArray.add(Mole.create(moleRegion));
        
        moleArray.add(Mole.create(moleRegion));
        moleArray.add(Mole.create(moleRegion));
        moleArray.add(Mole.create(moleRegion));
        
        table = super.getTable();
        table.add(moleArray.get(0));
        table.add(moleArray.get(1));
        table.add(moleArray.get(2));
        
        table.row();
        table.add(moleArray.get(3));
        table.add(moleArray.get(4));
        table.add(moleArray.get(5));
        
        table.row();
        table.add(moleArray.get(6));
        table.add(moleArray.get(7));
        table.add(moleArray.get(8));
        
        NinePatch background = new NinePatch(moleBackRegion);
        table.setBackground(background);
        
        //moleArray.get(0).showMole(0);
	}
	
	@Override
	public void resize(int width,int height )
    {
        super.resize( width, height );
        //moleArray.get(0).showMole(0);
    }
	
	@Override
    public void render(float delta )
    {
		
		Gdx.gl.glClearColor(1, 0, 0, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
        super.render( delta );
        //Gdx.app.log( "mole", Float.toString(moleArray.get(0).y));
        //if(moleArray.get(0).isAnimate == false) moleArray.get(0).showMole(delta);
        //if(moleArray.get(3).isAnimate == false) moleArray.get(3).showMole(delta);
        
        moleArray.get(0).showMole(delta);
        moleArray.get(4).showMole(delta);
        moleArray.get(8).showMole(delta);
        
        //batch.begin();
        //batch.draw(moleRegion, 100, 100);
        //batch.draw(moleRegion, 200, 100);
        //batch.draw(moleRegion, 300, 100);
        //batch.end();
    }
	
	@Override
    public void dispose()
    {
        super.dispose();
        moleTexture.dispose();
    }
	
	@Override
	public void resume(){
		super.resume();
		//moleArray.get(0).showMole(0);
	}
}
